<template>
	<view class="cust_detail">
		<view class="planinfo" v-for="(item,index) in plan_list" :key="index">
			<view class="planfir">
				<view class="name">{{item.num}}</view>
			</view>
			<view class="plansec"> 
				<view class="plantime">
					<view class="plantype">计划回款方式：{{item.return_type}}</view>
					<view class="plantype" style="padding-bottom: 34rpx;">计划回款日期：{{item.return_date}}</view>
				</view>
				<view class="planmoney">&yen;{{item.money}}</view>
			</view>
		</view>
		<view style="height: 200rpx;"></view>
		<u-empty v-if="plan_list.length == 0" text="暂无更多"></u-empty>
	</view>
</template>

<script>
	import {
		netContractFileList,
		netOperationList,
		netEditFileName,
		netPlanListf,
		netPaymentList
	} from '@/api/kehu.js'

	export default {
		data() {
			return {
				fileList: [], //附件列表
				opera_list: [], //操作记录
				plan_list: [], //回款计划 列表
				payment_list: [], //回款  列表 
				contactid: '', //合同id
			}
		},
		onLoad(options) {
			this.contactid = options.id
		},
		onShow() {
			//附件 列表
			this.getFile()
			//操作记录
			this.getOperalist()
			//获取  回款计划 列表
			this.getPlanlist()
			//获取  回款  列表 
			this.getPaymentlist()
		},
		methods: {
			//回款计划 列表
			getPlanlist() {
				netPlanListf({
					contract_id: this.contactid
				}).then(res => {
					this.plan_list = res.data.data
				})
				console.log(this.contactid)
				console.log(this.plan_list)
			},
			//添加 回款计划
			toAddPlan() {
				uni.navigateTo({
					url: '/pages/index/groupCompany/contract/addPaymentPlan?id=' + this.contactid
				})
			},
			//回款  列表
			getPaymentlist() {
				netPaymentList({
					contract_id: this.contactid
				}).then(res => {
					this.payment_list = res.data.data
				})

			},
			//添加  回款
			toAddPayment() {
				uni.navigateTo({
					url: '/pages/index/groupCompany/contract/addPayment?id=' + this.contactid
				})
			},
			// 回款  详情
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/index/groupCompany/contract/paymentDetail?id=' + id
				})
			},
			// 附件 列表 
			getFile() {
				let params = {
					contract_id: this.contactid
				}
				netContractFileList(params).then(res => {
					res.data.forEach(item => {
						item.disabled = true
						item.focus = false
					})
					this.fileList = res.data
				})
			},
			//操作 记录
			getOperalist() {
				let params = {
					relation_type: 3, //1客户  2联系人   3合同
					relation_id: this.contactid
				}
				netOperationList(params).then(res => {
					this.opera_list = res.data
				})
			},
			//编辑
			edit(index) {
				console.log(index)
				let obj = this.fileList[index]
				obj.disabled = false
				obj.focus = true
				this.fileList[index] = obj
			},
			changeName(e) {
				console.log(e)
				let name = e.detail.value
				let index = e.currentTarget.dataset.index
				let params = {
					id: this.fileList[index].id,
					name
				}
				netEditFileName(params).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(() => {
						this.getFile()
					}, 2000)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.cust_detail {
		.planinfo {
			margin-top: 20rpx;
			background: #fff;
			.planfir {
				border-bottom: 1px solid #ededed;
				.name {
					font-size: 34rpx;
					color: #333;
					padding: 28rpx 0 31rpx 63rpx;
				}
			}
			.plansec {
				display: flex;
				justify-content: space-between;
				.plantime {
					padding-left: 63rpx;
					.plantype {
						font-size: 26rpx;
						color: #999;
						margin-top: 34rpx;
					}
				}

				.planmoney {
					margin-right: 31rpx;
					margin-top: 63rpx;
					font-size: 34rpx;
					color: #03AA96;
					font-weight: 500;
				}
			}
		}
	}
</style>
